﻿package net.wangit.dev.wizard.unit;

import net.wangit.framework.config.WizardSettings;
import net.wangit.jdbc.ColumnRow;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.Table;
import net.wangit.util.Checker;

public class AQueryUnit {

	public AQueryUnit() {
	}

	public static final void create(DB db, String groupId, String unitId,
			String unitName, int accessible, String parentUnitId)
			throws Exception {
		Table table = new Table("dev", "UNIT");
		ColumnRow cRow = table.addInsertRow();
		cRow.set("uid", unitId);
		cRow.set("gid", groupId);
		cRow.set("c", 3);
		cRow.set("ti", unitName);
		cRow.set("st", 1);
		cRow.set("co", WizardSettings.instance().getQueryColumn());
		cRow.set("cc", WizardSettings.instance().getQueryColsConfig());
		if (!Checker.isEmpty(parentUnitId))
			cRow.set("pid", parentUnitId);
		cRow.set("ub", WizardSettings.instance().getQueryShowUnitBorder());
		cRow.set("tb", WizardSettings.instance().getQueryShowTitleBorder());
		cRow.set("gb", WizardSettings.instance().getQueryShowGridBorder());
		cRow.set("cb", WizardSettings.instance().getQueryShowCellBorder());
		cRow.set("pp", accessible);
		cRow.set("au", accessible);
		cRow.set("ms", "0");
		cRow.set("me", "1");
		cRow.set("ma", "0");
		cRow.set("l", "0");
		cRow.set("y", "0");
		db.save(table);
	}
}
